<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id

	+ Module  		: t_rapk View
	+ Description	: For record view
	+ Filename 		: v_t_rapk.php
 	+ creator  		: 
 	+ Created on 24/Jul/2012 10:52:52

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */
var t_kontrak_DataStore;
var t_kontrak_ColumnModel;
var t_kontrak_ListEditorGrid;
var t_kontrak_saveForm;
var t_kontrak_SelectedRow;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Kontrak";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Data Lanjut";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (html)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */
  	
  	Ext.util.Format.comboRenderer = function(combo){
  	    return function(value){
  	        var record = combo.findRecord(combo.valueField, value);
  	        return record ? record.get(combo.displayField) : combo.valueNotFoundText;
  	    };
  	};
  	
  	/* START DATA */
	t_add_datappn = new Ext.data.Store({
		id: 't_project_datappn',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_ppn',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'setup_ppn'
		},[
			{name: 'setup_ppn', type: 'int', mapping: 'setup_ppn'}
		]),
		sortInfo:{field: 'setup_ppn', direction: "ASC"}
	});
	t_add_datappn.load({params: {start: 0, limit: pageS}});
  	t_kontrak_DataStore = new Ext.data.Store({
		id: 't_kontrak_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_kontrak&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'spk_id'
		},[
			{name: 'spk_id', type: 'int', mapping: 'spk_id'},
			{name: 'branch_id', type: 'int', mapping: 'branch_id'},
			{name: 'branch_name', type: 'string', mapping: 'branch_name'},
			{name: 'project_id', type: 'int', mapping: 'project_id'},
			{name: 'project_name', type: 'string', mapping: 'project_name'},
			{name: 'project_code', type: 'string', mapping: 'project_code'},
			{name: 'job_id', type: 'int', mapping: 'job_id'},
			{name: 'm_div_id', type: 'int', mapping: 'm_div_id'},
			{name: 'job_name', type: 'string', mapping: 'job_name'},
			{name: 'vendor_id', type: 'int', mapping: 'vendor_id'},
			{name: 'vendor_name', type: 'string', mapping: 'vendor_name'},
			{name: 'vendor_address', type: 'string', mapping: 'vendor_address'},
			{name: 'spk_vendor1', type: 'string', mapping: 'spk_vendor1'},
			{name: 'kontrak_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'kontrak_date'},
			{name: 'kontrak_id', type: 'int', mapping: 'kontrak_id'},
			{name: 'kontrak_no', type: 'string', mapping: 'kontrak_no'},
			{name: 'kontrak_begin', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'kontrak_begin'},
			{name: 'kontrak_end', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'kontrak_end'}
		]),
		sortInfo:{field: 'project_code', direction: "ASC"}
	});
  	t_kontrak_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
  	
	var badet_reader=new Ext.data.JsonReader({
		root: 'results',
		totalProperty: 'total',
		id: 'kompdet_id'
	},[
	/* dataIndex => insert intoperawatan_ColumnModel, Mapping => for initiate table column */
			{name: 'kompdet_id', type: 'int', mapping: 'kompdet_id'},
			{name: 'komp_id', type: 'int', mapping: 'komp_id'},
			{name: 'jobdet_id', type: 'int', mapping: 'jobdet_id'}, 
			{name: 'jobdet_name', type: 'string', mapping: 'jobdet_name'},
			{name: 'kompdet_vol', type: 'float', mapping: 'kompdet_vol'},
			{name: 'unit_id', type: 'int', mapping: 'unit_id'},
			{name: 'unit_name', type: 'string', mapping: 'unit_name'},
			{name: 'kompdet_price', type: 'float', mapping: 'kompdet_price'}
	]);
	
	var badetDataStore = new Ext.data.Store({
		id: 'spkdetDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_kontrak&m=badet_list', 
			method: 'POST'
		}),
		reader: badet_reader
	});

	var pasalDataStore = new Ext.data.Store({
		id: 'pasalDataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_kontrak&m=get_pasal_all', 
			method: 'POST'
		}),
		baseParams:{task: "LIST"}, // parameter yang di $_POST ke Controller
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'pasal_id'
		},[
		/* dataIndex => insert intotbl_s_cabang_ColumnModel, Mapping => for initiate table column */ 
			{name: 'pasal_id', type: 'int', mapping: 'pasal_id'}, 
			{name: 'pasal_seq', type: 'int', mapping: 'pasal_seq'}, 
			{name: 'pasal_no', type: 'string', mapping: 'pasal_no'},
			{name: 'pasal_title', type: 'string', mapping: 'pasal_title'},
			{name: 'pasal_content', type: 'string', mapping: 'pasal_content'},
			{name: 'pasal_content_partial', type: 'string', mapping: 'pasal_content_partial'}
		])
	});
  	/* END DATA */
  	
  	
  	/* START FORM */
	//detail
	var kontrakdet_rapkdet_idField = new Ext.form.NumberField({
		id: 'kontrakdet_rapkdet_idField',
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		maskRe: /([0-9]+)$/
	});

	var kontrak_jumlah_cfField = new Ext.form.TextField({
		id: 'kontrak_jumlah_cfField',
		fieldLabel: 'Jumlah ',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		maskRe: /([0-9]+)$/ 
	});

	var kontrak_ppn_cfField = new Ext.form.TextField({
		id: 'kontrak_ppn_cfField',
		fieldLabel: 'PPN ',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		maskRe: /([0-9]+)$/ 
	});
	
	var kontrak_nk_cfField = new Ext.form.TextField({
		id: 'kontrak_nk_cfField',
		fieldLabel: '<span style="font-weight:bold">NK (Rp)</span>',
		allowNegatife : false,
		enableKeyEvents: true,
		itemCls: 'rmoney',
		width: 160,
		maskRe: /([0-9]+)$/ 
	});
	
	var kontrak_jobdet_totalGroup = new Ext.form.FieldSet({
		title: '-',
		labelWidth: 140,
		autoHeight: true,
		collapsible: false,
		layout:'form',
		frame: true,
		items:[kontrak_jumlah_cfField, kontrak_ppn_cfField, kontrak_nk_cfField]
	});
	
	//column model jobdet
	var badetColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'Jenis, Merk, dan Ukuran Material',
			id: 'jobdet_jenis_merk_ukuran',
			dataIndex: 'jobdet_name'
		},
		{
			header: 'Volume',
			dataIndex: 'kompdet_vol',
			width: 90,
			sortable: false,
			align: 'right',
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Satuan',
			dataIndex: 'unit_name',
			width: 90,
			sortable: false
		},
		{
			header: 'Harga',
			dataIndex: 'kompdet_price',
			width: 90,
			sortable: false,
			align: 'right',
			renderer: Ext.util.Format.numberRenderer('0.000/i')
		},
		{
			header: 'Jumlah',
			width: 100,
			sortable: false,
			align: 'right',
			renderer: function(v, params, record){
				return Ext.util.Format.number(record.data.kompdet_vol * record.data.kompdet_price,'0.000/i');
            }
		}]
	);
	badetColumnModel.defaultSortable= true;
	
	//detail list editor grid jobdet
	var badetListGrid =  new Ext.grid.GridPanel({
		id: 'spkdetListGrid',
		//el: 'fp_m_jobdet',
		title: 'Detail Jenis Pekerjaan',
		height: 250,
		width: 780,
		autoScroll: true,
		store: badetDataStore, // DataStore
		colModel: badetColumnModel, // Nama-nama Columns
		enableColLock:false,
		region: 'center',
        margins: '0 5 5 5',
		frame: true,
		autoExpandColumn: 'jobdet_jenis_merk_ukuran',
		//clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:false},
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: badetDataStore,
			displayInfo: true
		}),
	});
	
	
	//Form Create/Update
	var kontrak_idField = new Ext.form.NumberField({
		id: 'kontrak_idField',
		fieldLabel: 'Kontrak Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	var t_spk_idField = new Ext.form.NumberField({
		id: 't_spk_idField',
		fieldLabel: 'spk Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	var kontrak_branchField = new Ext.form.TextField({
		id: 'kontrak_branchField',
		fieldLabel: 'Cabang',
		readOnly: true,
		width: 250
	});
	var kontrak_projectField = new Ext.form.TextField({
		id: 'kontrak_projectField',
		fieldLabel: 'Kode Proyek',
		readOnly: true,
		width: 250
	});
	var kontrak_projectNameField = new Ext.form.TextField({
		id: 'kontrak_projectNameField',
		fieldLabel: 'Nama Proyek',
		width: 250,
		readOnly: true
	});
	var kontrak_jobField = new Ext.form.TextField({
		id: 'kontrak_jobField',
		fieldLabel: 'Pengadaan',
		readOnly: true,
		width: 250
	});
	var kontrak_vendorField = new Ext.form.TextField({
		id: 'kontrak_vendorField',
		fieldLabel: 'Nama Subkont',
		maxLength: 45,
		readOnly: true,
		width: 250
	});
	var kontrak_vendor_addressField = new Ext.form.TextArea({
		id: 'kontrak_vendor_addressField',
		fieldLabel: 'Alamat',
		readOnly: true,
		width: 250
	});
	var kontrak_vendor_wakilField = new Ext.form.TextField({
		id: 'kontrak_vendor_wakilField',
		fieldLabel: 'Wakil Subkont',
		maxLength: 45,
		readOnly: true,
		width: 250
	});
	var kontrak_dateField = new Ext.form.DateField({
		id: 'kontrak_dateField',
		fieldLabel: 'Tgl Kontrak',
		format : 'l, F d, Y',
		allowBlank: false,
		width: 250
	});
	var kontrak_noField = new Ext.form.TextField({
		id: 'kontrak_noField',
		fieldLabel: 'No. Kontrak',
		maxLength: 45,
		allowBlank: false,
		width: 170
	});
	var kontrak_btnsearch_noField= new Ext.Button({
		tooltip: 'Apakah No. Surat sudah pernah digunakan?',
		iconCls:'icon-search',
		handler: nokontrak_validation
	});
	var kontrak_labelvalidornot = new Ext.form.Label({
		id: 'kontrak_labelvalidornot',
		style: {
			marginLeft : '10px',
			marginTop: '5px'
		}
	});
	var kontrak_pelaksanaan_datestartField= new Ext.form.DateField({
		id: 'kontrak_pelaksanaan_datestartField',
		fieldLabel: 'Waktu Pelaksanaan',
		format : 'l, F d, Y',
		allowBlank: false,
		width: 200
	});
	var kontrak_pelaksanaan_dateendField= new Ext.form.DateField({
		id: 'kontrak_pelaksanaan_dateendField',
		fieldLabel: 's/d',
		format : 'l, F d, Y',
		allowBlank: false,
		width: 200
	});
	
	var t_kontrak_btn_Save = new Ext.Button({
		text: BTN_SAVE,
		handler: t_kontrak_save
	});
	t_kontrak_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' Project',
		bodyStyle:'padding:5px',
		autoHeight:true,
		width: 800,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_t_kontrak_save',
		layout:'form',
		items:[{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[kontrak_idField ,t_spk_idField ,kontrak_branchField ,kontrak_projectField ,kontrak_projectNameField ,kontrak_jobField, kontrak_dateField,
						{
							layout: 'column',
							border: false,
							items:[{
								columnWidth:0.70,
								layout: 'form',
								border:false,
								items:[kontrak_noField]
							},{
								columnWidth:0.30,
								layout: 'column',
								border:false,
								items: [kontrak_btnsearch_noField,kontrak_labelvalidornot]
							}]
						}]
			},{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items:[kontrak_vendorField, kontrak_vendor_addressField, kontrak_vendor_wakilField]
			}]
		},{
			layout: 'column',
			border: false,
			items:[{
				columnWidth:0.45,
				layout: 'form',
				border:false,
				labelWidth: 130,
				items:[kontrak_pelaksanaan_datestartField]
			},{
				columnWidth:0.55,
				layout: 'form',
				border:false,
				labelWidth: 25,
				items: [kontrak_pelaksanaan_dateendField]
			}]
		},badetListGrid ,kontrak_jobdet_totalGroup 
		,new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED }) ],
		buttons: [t_kontrak_btn_Save
			,{
				text: BTN_CANCEL,
				handler: function(){
					t_kontrak_reset_form();
				}
			}
		]
	});
	
	//start main grid panel
	t_kontrak_ColumnModel = new Ext.grid.ColumnModel(
		[{
			header: 'Project Id',
			dataIndex: 'kontrak_id',
			width: 150,
			sortable: false,
			hidden: true
		},
		{
			header: 'Cabang',
			dataIndex: 'branch_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Kode Proyek',
			dataIndex: 'project_code',
			width: 150,
			sortable: false
		},
		{
			header: 'Nama Proyek',
			dataIndex: 'project_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Pengadaan',
			dataIndex: 'job_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Nama Pemenang',
			dataIndex: 'vendor_name',
			width: 150,
			sortable: false
		},
		{
			header: 'Nomor Kontrak',
			dataIndex: 'kontrak_no',
			width: 150,
			sortable: false
		},
		{
			header: 'Id Vendor',
			dataIndex: 'vendor_id',
			hidden : true,
			sortable: false
		}	]);

	t_kontrak_ColumnModel.defaultSortable= true;
	/* End of Function */

    /* Button Control */
    t_kontrak_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_kontrak_confirm_update
	});

    t_kontrak_gbtn_cetak=new Ext.Button({
	    text: 'Cetak',
		tooltip: 'Cetak PDF',
		iconCls:'icon-update',
		disabled: true,
		handler: function(){
			var ba_id_field = t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('spk_id');
			var branch_id_field = t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('branch_id');
			var project_id_field = t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('project_id');
			var job_id_field = t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('job_id');
			
			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_t_kontrak&m=kontrak_print',
				params: {
					spk_id: ba_id_field
					//branch_id: branch_id_field,
					//project_id: project_id_field,
					//job_id: job_id_field
				},
				success: function(response){
					win = window.open('./print/kontrak.doc', '_blank');
				},
				failure: function(response){
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});
		}
	});
	
	t_kontrak_gbtn_editpasal=new Ext.Button({
	    text: 'Edit Pasal',
		tooltip: 'Edit Pasal',
		handler: pasal_edit,
		iconCls:'icon-refresh',
		disabled : true
	});
	
	t_kontrak_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_kontrak_ListEditorGrid',
		el: 'fp_t_kontrak',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: t_kontrak_DataStore, // DataStore
		cm: t_kontrak_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 1024,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: t_kontrak_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		t_kontrak_gbtn_update, '-',
		t_kontrak_gbtn_cetak, '-',
		new Ext.app.SearchField({
			store: t_kontrak_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						t_kontrak_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		}),'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: t_kontrak_reset_search,
			iconCls:'icon-refresh'
		},'-',t_kontrak_gbtn_editpasal/*,'-',{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: t_kontrak_export_excel
		}, '-',{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: t_kontrak_print
		}*/
		]
	});
	t_kontrak_ListEditorGrid.render();
	t_kontrak_ListEditorGrid.on('click', function(){
		if(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_no') === null || t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_no') === ""){
			t_kontrak_gbtn_update.enable();
			t_kontrak_gbtn_cetak.disable();
			t_kontrak_gbtn_editpasal.disable();
		}else{
			t_kontrak_gbtn_update.disable();
			t_kontrak_gbtn_cetak.enable();
			t_kontrak_gbtn_editpasal.enable();
		}
	});

	//list to editing pasal
	var pasal_grid = new Ext.grid.GridPanel({
        store: pasalDataStore,
        columns: [
            {
                header   : 'ID', 
                width    : 60, 
                sortable : false, 
                hidden   : true,
                dataIndex: 'pasal_id'
            },
            {
                header   : 'No', 
                width    : 50, 
                sortable : false, 
                dataIndex: 'pasal_no'
            },
            {
                header   : 'Judul', 
                width    : 200, 
                sortable : false, 
                dataIndex: 'pasal_title'
            },
            {
            	id		 : 'pasal_content',
                header   : 'Isi', 
                width    : 100, 
                sortable : false, 
                dataIndex: 'pasal_content_partial',
                renderer : function(val){
                	return '<div style="white-space:normal !important;">'+ val +'</div>';
                }
            },
            {
                xtype: 'actioncolumn',
                width: 30,
                items: [{
                    icon   : './assets/images/icons/pencil.png',  // Use a URL in the icon config
                    tooltip: 'Sell stock',
                    handler: function(grid, rowIndex, colIndex) {
                        var rec = pasalDataStore.getAt(rowIndex);
                        //alert("Sell " + rec.get('pasal_id'));
                        pasal_edit_set_form(rec.get('pasal_id'), rec.get('pasal_no'), rec.get('pasal_content'));
                        pasal_editWindow.show();
                    }
                }]
            }
        ],
        stripeRows: true,
        autoExpandColumn: 'pasal_content',
        autoHeight: true
    });
	pasal_listForm = new Ext.FormPanel({
		labelAlign: 'left',
		bodyStyle:'padding:0px',
		autoHeight:true,
		width: 900,
		items:[pasal_grid],
		buttons:[{
			text: 'Selesai',
			handler: function(){
				pasal_listWindow.hide();
			}
		}]
	});
	pasal_listWindow = new Ext.Window({
		id: 'pasal_listWindow',
		title: 'Edit Pasal',
		closable:true,
		closeAction: 'hide',
		width: 1120,
		autoHeight: true,
		x:0,
		y:0,
		plain:true,
		layout: 'fit',
		modal: true,
		renderTo: 'elwindow_pasal_list',
		items: pasal_listForm
	});

	//editing pasal
	var pasal_editIdField = new Ext.form.NumberField({
		id: 'pasal_editIdField',
		allowDecimals: true,
		allowNegative: false,
		blankText: '0',
		hidden: true,
		maskRe: /([0-9]+)$/
	});
	var pasal_editNoField = new Ext.form.TextField({
		id: 'pasal_editNoField',
		fieldLabel: 'No. Pasal',
		readOnly: true,
		width: 250
	});
	var pasal_editContentField = new Ext.ux.TinyMCE({
		fieldLabel: 'Isi Pasal',
		hideLabel: false,
		tinymceSettings: {
			mode : "textareas",
			theme : "advanced",
			plugins : "autolink,lists,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist,autosave,visualblocks",
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,code,|,insertdate,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "none",
			theme_advanced_resizing : false,
			theme_advanced_source_editor_height : 500
			//theme_advanced_path : false//,
			//extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]"
		},
		width: "98%",
		height: "420",
		value: "<h1>Demo</h1><p>Ext.ux.TinyMCE works...</p>"
	});
	pasal_editForm = new Ext.FormPanel({
		labelAlign: 'left',
		bodyStyle:'padding:0px',
		autoHeight:true,
		width: 900,
		frame: true,
		items:[pasal_editIdField, pasal_editNoField, pasal_editContentField],
		buttons:[{
			text: 'Simpan',
			handler: pasal_edit_save
		},{
			text: 'Batal',
			handler: function(){
				pasal_editWindow.hide();
			}
		}]
	});
	pasal_editWindow = new Ext.Window({
		id: 'pasal_editWindow',
		title: 'Editing Pasal',
		closable:true,
		closeAction: 'hide',
		width: 1120,
		autoHeight: true,
		x:0,
		y:0,
		plain:true,
		layout: 'fit',
		modal: true,
		renderTo: 'elwindow_pasal_edit',
		items: pasal_editForm
	});
  	/* END FORM */
  	
  	
  	/* START FUNCTION */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_id');
		return 0;
	}
	
	//validation form
	function is_t_kontrak_form_valid(){
		return (kontrak_dateField.isValid() && kontrak_noField.isValid() && kontrak_pelaksanaan_datestartField.isValid() && kontrak_pelaksanaan_dateendField.isValid());
	}
	
	//saving data
	function t_kontrak_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{
			if(is_t_kontrak_form_valid()){
				var kontrak_id_field=null;
				var t_spk_id_field=null;
				var kontrak_date_field="";
				var kontrak_no_field=null;
				var kontrak_begin_field="";
				var kontrak_end_field="";
				var kontrak_type = "";
				
				if(t_kontrak_ListEditorGrid.getSelectionModel().getSelected()!== null){kontrak_type = t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('m_div_id');}
				if(kontrak_idField.getValue()!== null){kontrak_id_field = kontrak_idField.getValue();}
				if(t_spk_idField.getValue()!== null){t_spk_id_field = t_spk_idField.getValue();}
				if(kontrak_dateField.getValue()!==""){kontrak_date_field = kontrak_dateField.getValue().format('Y-m-d');}
				if(kontrak_noField.getValue()!== null){kontrak_no_field = kontrak_noField.getValue();}
				if(kontrak_pelaksanaan_datestartField.getValue()!==""){kontrak_begin_field = kontrak_pelaksanaan_datestartField.getValue().format('Y-m-d');}
				if(kontrak_pelaksanaan_dateendField.getValue()!==""){kontrak_end_field = kontrak_pelaksanaan_dateendField.getValue().format('Y-m-d');}
				
	
				Ext.Ajax.request({
					waitMsg: 'Please wait...',
					url: 'index.php?c=c_t_kontrak&m=t_kontrak_cu',
					params: {
						kontrak_id	: kontrak_id_field,
						t_spk_id: t_spk_id_field,
						kontrak_date: kontrak_date_field,
						kontrak_no: kontrak_no_field,
						kontrak_begin: kontrak_begin_field,
						kontrak_end: kontrak_end_field,
						kontrak_type : kontrak_type
					},
					success: function(response){
						var result=eval(response.responseText);
						switch(result){
							case 1:
								Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
								t_kontrak_DataStore.reload();
								t_kontrak_reset_form();
								break;
							default:
								Ext.MessageBox.show({
								   title: 'Warning',
								   msg: FAILED_SAVE,
								   buttons: Ext.MessageBox.OK,
								   animEl: 'save',
								   icon: Ext.MessageBox.WARNING
								});
								break;
						}
					},
					failure: function(response){
						Ext.MessageBox.show({
							   title: 'Error',
							   msg: FAILED_CONNECTION,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'database',
							   icon: Ext.MessageBox.ERROR
						});
					}
				});
	
			} else {
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_VALID_FORM,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
			}

		}
	}
	
	//reset form
	function t_kontrak_reset_form(){
		
		kontrak_labelvalidornot.setText('');
		kontrak_idField.reset();
		kontrak_idField.setValue(null);
		t_spk_idField.reset();
		t_spk_idField.setValue(null);
		kontrak_projectField.reset();
		kontrak_projectField.setValue(null);
		kontrak_projectNameField.reset();
		kontrak_projectNameField.setValue(null);
		kontrak_branchField.reset();
		kontrak_branchField.setValue(null);
		kontrak_nk_cfField.reset();
		kontrak_nk_cfField.setValue(null);
		kontrak_jumlah_cfField.reset();
		kontrak_jumlah_cfField.setValue(null);
		kontrak_ppn_cfField.reset();
		kontrak_ppn_cfField.setValue(null);
		kontrak_jobField.reset();
		kontrak_jobField.setValue(null);
		kontrak_vendorField.reset();
		kontrak_vendorField.setValue(null);
		kontrak_vendor_addressField.reset();
		kontrak_vendor_addressField.setValue(null);
		kontrak_vendor_wakilField.reset();
		kontrak_vendor_wakilField.setValue(null);
		kontrak_dateField.reset();
		kontrak_dateField.setValue(null);
		kontrak_noField.reset();
		kontrak_noField.setValue(null);
		kontrak_pelaksanaan_datestartField.reset();
		kontrak_pelaksanaan_datestartField.setValue(null);
		kontrak_pelaksanaan_dateendField.reset();
		kontrak_pelaksanaan_dateendField.setValue(null);
		badetListGrid.getStore().removeAll();
	}
	
	//set form
	function t_kontrak_set_form(){
		kontrak_labelvalidornot.setText('');
		kontrak_idField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_id'));
		t_spk_idField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('spk_id'));
		kontrak_branchField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('branch_name'));
		kontrak_projectField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('project_code'));
		kontrak_projectNameField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('project_name'));
		kontrak_jobField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('job_name'));
		kontrak_vendorField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('vendor_name'));
		kontrak_dateField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_date'));
		kontrak_noField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_no'));
		kontrak_noField.setReadOnly(false);
		kontrak_vendor_addressField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('vendor_address'));
		kontrak_vendor_wakilField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('spk_vendor1'));

		kontrak_dateField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_date'));
		kontrak_noField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_no'));
		kontrak_pelaksanaan_datestartField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_begin'));
		kontrak_pelaksanaan_dateendField.setValue(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_end'));

		if(t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_id') == 0){
			kontrak_dateField.enable();
			kontrak_noField.setReadOnly(false);
			kontrak_pelaksanaan_datestartField.enable();
			kontrak_pelaksanaan_dateendField.enable();
		}else{
			kontrak_dateField.disable();
			kontrak_noField.setReadOnly(false);
			kontrak_pelaksanaan_datestartField.disable();
			kontrak_pelaksanaan_dateendField.disable();
		}

		badetDataStore.setBaseParam('branch_id', t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('branch_id'));
		badetDataStore.setBaseParam('project_id', t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('project_id'));
		badetDataStore.setBaseParam('job_id', t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('job_id'));
		badetDataStore.setBaseParam('vendor_id', t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('vendor_id'));
		badetDataStore.load({
			callback: function(opts, success, response){
				var detail_total = 0;
				for(var i=0; i<badetDataStore.getCount(); i++){
					detail_total += (badetDataStore.getAt(i).data.kompdet_vol * badetDataStore.getAt(i).data.kompdet_price);
				}
				kontrak_jumlah_cfField.setValue(formatCurrency(detail_total));

				var ppn_datarecord = t_add_datappn.getAt(0).data;
				var ppn = ppn_datarecord.setup_ppn;
				var ppn_nilai = detail_total * ppn / 100;
				
				kontrak_ppn_cfField.setValue(formatCurrency(ppn_nilai));
				
				kontrak_nk_cfField.setValue(formatCurrency(detail_total + ppn_nilai));
				kontrak_jumlah_cfField.setReadOnly(true);
				kontrak_ppn_cfField.setReadOnly(true);
				kontrak_nk_cfField.setReadOnly(true);
			}
		});
	}
	
	//update main grid
	function t_kontrak_confirm_update(){
		/* only one record is selected here */
		if(t_kontrak_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			t_kontrak_set_form();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
	
	//reset searching
	function t_kontrak_reset_search(){
		t_kontrak_DataStore.baseParams = { task: 'LIST' };
		t_kontrak_DataStore.reload({params: {start: 0, limit: pageS}});
	};
	
	//printing
	function t_kontrak_print(){
		var searchquery = "";
		var kontrak_id_print=null;
		var kontrak_flag_print=null;
		var kontrak_code_print=null;
		var kontrak_type_print=null;
		var kontrak_name_print=null;
		var kontrak_shortname_print=null;
		var kontrak_pm_print=null;
		var kontrak_semcm_print=null;
		var kontrak_value_print=null;
		var kontrak_start_print_date="";
		var kontrak_p1_print_date="";
		var kontrak_p2_print_date="";
		var m_branch_print=null;

		if(t_kontrak_DataStore.baseParams.query!==null){searchquery = t_kontrak_DataStore.baseParams.query;}
		if(t_kontrak_DataStore.baseParams.kontrak_id!==null){kontrak_id_print = t_kontrak_DataStore.baseParams.kontrak_id;}
		if(t_kontrak_DataStore.baseParams.kontrak_flag!==null){kontrak_flag_print = t_kontrak_DataStore.baseParams.kontrak_flag;}
		if(t_kontrak_DataStore.baseParams.kontrak_code!==null){kontrak_code_print = t_kontrak_DataStore.baseParams.kontrak_code;}
		if(t_kontrak_DataStore.baseParams.kontrak_type!==null){kontrak_type_print = t_kontrak_DataStore.baseParams.kontrak_type;}
		if(t_kontrak_DataStore.baseParams.kontrak_name!==null){kontrak_name_print = t_kontrak_DataStore.baseParams.kontrak_name;}
		if(t_kontrak_DataStore.baseParams.kontrak_shortname!==null){kontrak_shortname_print = t_kontrak_DataStore.baseParams.kontrak_shortname;}
		if(t_kontrak_DataStore.baseParams.kontrak_pm!==null){kontrak_pm_print = t_kontrak_DataStore.baseParams.kontrak_pm;}
		if(t_kontrak_DataStore.baseParams.kontrak_semcm!==null){kontrak_semcm_print = t_kontrak_DataStore.baseParams.kontrak_semcm;}
		if(t_kontrak_DataStore.baseParams.kontrak_value!==null){kontrak_value_print = t_kontrak_DataStore.baseParams.kontrak_value;}
		if(t_kontrak_DataStore.baseParams.kontrak_start!==""){kontrak_start_print_date = t_kontrak_DataStore.baseParams.kontrak_start;}
		if(t_kontrak_DataStore.baseParams.kontrak_p1!==""){kontrak_p1_print_date = t_kontrak_DataStore.baseParams.kontrak_p1;}
		if(t_kontrak_DataStore.baseParams.kontrak_p2!==""){kontrak_p2_print_date = t_kontrak_DataStore.baseParams.kontrak_p2;}
		if(t_kontrak_DataStore.baseParams.m_branch!==null){m_branch_print = t_kontrak_DataStore.baseParams.m_branch;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_kontrak&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,
			kontrak_id : kontrak_id_print,
			kontrak_flag : kontrak_flag_print,
			kontrak_code : kontrak_code_print,
			kontrak_type : kontrak_type_print,
			kontrak_name : kontrak_name_print,
			kontrak_shortname : kontrak_shortname_print,
			kontrak_pm : kontrak_pm_print,
			kontrak_semcm : kontrak_semcm_print,
			kontrak_value : kontrak_value_print,
		  	kontrak_start : kontrak_start_print_date,
		  	kontrak_p1 : kontrak_p1_print_date,
		  	kontrak_p2 : kontrak_p2_print_date,
			m_branch : m_branch_print,
		  	currentlisting: t_kontrak_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				window.open('./print/t_kontrak_printlist.html','t_kontraklist','height=600,width=800,resizable=1,scrollbars=0, menubar=0');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_PRINT,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	
	//exporting excel
	function t_kontrak_export_excel(){
		var searchquery = "";
		var kontrak_id_2excel=null;
		var kontrak_flag_2excel=null;
		var kontrak_code_2excel=null;
		var kontrak_type_2excel=null;
		var kontrak_name_2excel=null;
		var kontrak_shortname_2excel=null;
		var kontrak_pm_2excel=null;
		var kontrak_semcm_2excel=null;
		var kontrak_value_2excel=null;
		var kontrak_start_2excel_date="";
		var kontrak_p1_2excel_date="";
		var kontrak_p2_2excel_date="";
		var m_branch_2excel=null;

		if(t_kontrak_DataStore.baseParams.query!==null){searchquery = t_kontrak_DataStore.baseParams.query;}
		if(t_kontrak_DataStore.baseParams.kontrak_id!==null){kontrak_id_2excel = t_kontrak_DataStore.baseParams.kontrak_id;}
		if(t_kontrak_DataStore.baseParams.kontrak_flag!==null){kontrak_flag_2excel = t_kontrak_DataStore.baseParams.kontrak_flag;}
		if(t_kontrak_DataStore.baseParams.kontrak_code!==null){kontrak_code_2excel = t_kontrak_DataStore.baseParams.kontrak_code;}
		if(t_kontrak_DataStore.baseParams.kontrak_type!==null){kontrak_type_2excel = t_kontrak_DataStore.baseParams.kontrak_type;}
		if(t_kontrak_DataStore.baseParams.kontrak_name!==null){kontrak_name_2excel = t_kontrak_DataStore.baseParams.kontrak_name;}
		if(t_kontrak_DataStore.baseParams.kontrak_shortname!==null){kontrak_shortname_2excel = t_kontrak_DataStore.baseParams.kontrak_shortname;}
		if(t_kontrak_DataStore.baseParams.kontrak_pm!==null){kontrak_pm_2excel = t_kontrak_DataStore.baseParams.kontrak_pm;}
		if(t_kontrak_DataStore.baseParams.kontrak_semcm!==null){kontrak_semcm_2excel = t_kontrak_DataStore.baseParams.kontrak_semcm;}
		if(t_kontrak_DataStore.baseParams.kontrak_value!==null){kontrak_value_2excel = t_kontrak_DataStore.baseParams.kontrak_value;}
		if(t_kontrak_DataStore.baseParams.kontrak_start!==""){kontrak_start_2excel_date = t_kontrak_DataStore.baseParams.kontrak_start;}
		if(t_kontrak_DataStore.baseParams.kontrak_p1!==""){kontrak_p1_2excel_date = t_kontrak_DataStore.baseParams.kontrak_p1;}
		if(t_kontrak_DataStore.baseParams.kontrak_p2!==""){kontrak_p2_2excel_date = t_kontrak_DataStore.baseParams.kontrak_p2;}
		if(t_kontrak_DataStore.baseParams.m_branch!==null){m_branch_2excel = t_kontrak_DataStore.baseParams.m_branch;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_kontrak&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,
			kontrak_id : kontrak_id_2excel,
			kontrak_flag : kontrak_flag_2excel,
			kontrak_code : kontrak_code_2excel,
			kontrak_type : kontrak_type_2excel,
			kontrak_name : kontrak_name_2excel,
			kontrak_shortname : kontrak_shortname_2excel,
			kontrak_pm : kontrak_pm_2excel,
			kontrak_semcm : kontrak_semcm_2excel,
			kontrak_value : kontrak_value_2excel,
		  	kontrak_start : kontrak_start_2excel_date,
		  	kontrak_p1 : kontrak_p1_2excel_date,
		  	kontrak_p2 : kontrak_p2_2excel_date,
			m_branch : m_branch_2excel,
		  	currentlisting: t_kontrak_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
		  		window.open('./print/t_kontrak_printlist.xls');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_EXCEL,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	
	function nokontrak_validation(){
		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_t_kontrak&m=get_nokontrak',
			params: {
				nokontrak: kontrak_noField.getValue()
			},
			success: function(response){
				var result=eval(response.responseText);
				if(result==0){
					/* Ext.MessageBox.show({
					   title: 'Warning',
					   msg: 'No. Kontrak tidak valid!',
					   buttons: Ext.MessageBox.OK,
					   animEl: 'save',
					   icon: Ext.MessageBox.WARNING
					}); */
					kontrak_labelvalidornot.setText('Invalid');
					kontrak_noField.reset();
					kontrak_noField.setValue(null);
				}else{
					kontrak_labelvalidornot.setText('Valid');
				}
			},
			failure: function(response){
				Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
				});
			}
		});
	}

	function pasal_edit(){
		var kontrak_no = t_kontrak_ListEditorGrid.getSelectionModel().getSelected().get('kontrak_no');
		pasalDataStore.reload({params:{'kontrak_no':kontrak_no}});
		pasal_listWindow.show();
	}

  	function pasal_edit_set_form(id, no, content){
  		if (typeof id == "undefined") {
  	  	    id = 0;
  	  	}
  		if (typeof no == "undefined") {
  	  	    no = "";
  	  	}
		if (typeof content == "undefined") {
  	  	    content = "Tidak ada data";
  	  	}

		pasal_editIdField.setValue(id);
		pasal_editNoField.setValue(no);
		pasal_editContentField.setValue(content);
  	}

  	function pasal_edit_reset_form(){
  		pasal_editIdField.reset();
  		pasal_editIdField.setValue(null);
  		pasal_editNoField.reset();
		pasal_editNoField.setValue(null);
		pasal_editContentField.reset();
		pasal_editContentField.setValue("");
  	}

  	function pasal_edit_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{
			var pasal_id_field=0;
			var pasal_content_field="";

			if(pasal_editIdField.getValue()!==null && pasal_editIdField.getValue()!==""){pasal_id_field = pasal_editIdField.getValue();}
			if(pasal_editContentField.getValue()!== null){pasal_content_field = pasal_editContentField.getValue();}

			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_t_kontrak&m=pasal_edit_save',
				params: {
					pasal_id	: pasal_id_field,
					pasal_content: pasal_content_field
				},
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							Ext.MessageBox.alert(' OK',SUCCESS_SAVE);
							pasalDataStore.reload();
							pasal_edit_reset_form();
							pasal_editWindow.hide();
							break;
						default:
							Ext.MessageBox.show({
							   title: 'Warning',
							   msg: FAILED_SAVE,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'save',
							   icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});
	

		}
	}
	function set_valueplusppn(value){
		var ppn_datarecord = t_add_datappn.getAt(0).data;
		var ppn = ppn_datarecord.setup_ppn;
		var ppn_nilai = value * ppn / 100;
		var valueminppn = value - ppn_nilai;
		return valueminppn;
	}
  	/* END FUNCTION */

	/* START CONTROL PERMISSION */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	if(pattc.test(PERMISSION)==false){
		
	}else{
		
	}

	if(pattu.test(PERMISSION)==false){
		t_kontrak_gbtn_update.setVisible(false);
	}else{
		t_kontrak_gbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		
	}else{
		
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		t_kontrak_btn_Save.setVisible(false);
	}else{
		t_kontrak_btn_Save.setVisible(true);
	}
	/* END CONTROL PERMISSION */
	
});
</script>
<body style: 'spkckground: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_t_kontrak_save"></div>
		<div>&nbsp;</div>
		<div id="fp_t_kontrak"></div>
		<div id="elwindow_pasal_list"></div>
        <div id="elwindow_pasal_edit"></div>
    </div>
</div>
</body>
</html>